package com.thomasmoerman.dci.tmc

import org.squeryl.PrimitiveTypeMode._

trait Transactional {
  this: TransactionManagerComponent with SessionFactory =>
  
  def transactionally[A](block: => A): A = {
	var rollback: Boolean = false
	
	try {
	  beginTransaction
	  
	  using(session) {block}
	} catch {
	  case e => rollback = true
	  
	  throw e
	} finally {
	  if (rollback) rollbackTransaction else commitTransaction
	}
  }
  
}